﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Account.Model;
using Yipusoft.MapInfo.Model;
using Yipusoft.Account.BLL;

public partial class MapInfo_DepartmentInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            Bind();
    }

    private void Bind()
    {
        string DepartmentID = string.Empty;
        if (Request["departmentID"] != null)
        {
            if (!Request["DepartmentID"].Substring(0, 2).Equals("13"))
                DepartmentID = "13" + Request["departmentID"];
            else
                DepartmentID = Request["departmentID"];

            //List<Yipusoft.MapInfo.Model.DepartmentPhotoInfo>list=  Yipusoft.MapInfo.BLL.DepartmentPhoto.GetPhotoListByDepartmentID(DepartmentID);
            //DepartmentInfo Info= Yipusoft.Account.BLL.Department.GetDepartment(DepartmentID);
            //if (Info != null)
            //{
            //    Yipusoft.MapInfo.Model.DepartmentPhotoInfo PhotoInfo = null;

            //    if (list.Where(o => o.PhotoName.Equals(Info.FullName)).Count() <= 0)
            //        return;

            //    if (list.Where(o => o.PhotoName.Equals(Info.FullName)).Count() > 0 && list.Where(o => o.PhotoName.Equals(Info.FullName)).Count() == 1)
            //    {
            //        PhotoInfo = list.Where(o => o.PhotoName.Equals(Info.FullName)).Single();
            //    }
            //    else
            //    {
            //        PhotoInfo = list[0];
            //    }


            //    if (PhotoInfo != null)
            //    {
            //        DepartmentImage.ImageUrl = PhotoInfo.PhotoUrl;

            //        lblInfo.Text = PhotoInfo.PhotoDetails;
            //    }
            //}
            Yipusoft.MapInfo.Model.DepartmentIntroInfo info = Yipusoft.MapInfo.BLL.DepartmentIntroduce.GetModel(DepartmentID);
            if (info == null)
                return;

            ShowInfo(info);
		
            if (DepartmentID.Substring(4, 1) == "3")
            {
                string DepartmentName = Department.GetDepartment(DepartmentID).FullName;
                if (!DepartmentName.Contains("特勤"))
                {
                    TreeList.Nodes.Add(new TreeNode("8、抢险救援班", "抢险救援班"));
                }
                TreeList.Nodes.Add(new TreeNode("9、灭火抢险救援专业队伍", "灭火抢险救援专业队伍"));
                TreeList.Nodes.Add(new TreeNode("10、灭火攻坚组", "灭火攻坚组"));

            }

        }

    }

    private void ShowInfo(DepartmentIntroInfo model)
    {

        this.lblDepartmentName.Text = model.DepartmentName;
        this.lblDepartmentAddress.Text = model.DepartmentAddress;
        this.lblCreateDate.Text = model.CreateDate.Value.ToShortDateString();
        this.lblDepartmentAreaSize.Text = model.DepartmentAreaSize.ToString() + "平方米";
        this.lblBuildAreaSize.Text = model.BuildAreaSize.ToString() + "平方米";
        this.lblPeopleCount.Text = model.PeopleCount.ToString().Trim() != "" ? model.PeopleCount.ToString().Trim() + "人" : "";
        this.lblOfficerCount.Text = model.OfficerCount.ToString().Trim() != "" ? model.OfficerCount.ToString() + "人" : "";
        this.lblContractCount.Text = model.ContractCount.ToString().Trim() != "" ? model.ContractCount.ToString() + "人" : "";
        this.lblEmployeeCount.Text = model.EmployeeCount.ToString().Trim() != "" ? model.EmployeeCount.ToString().Trim() + "人" : "";
        this.lblCarbarnCount.Text = model.CarbarnCount.ToString().Trim() != "" ? model.CarbarnCount.ToString() + "间" : "";
        this.lblDutyCarCount.Text = model.DutyCarCount.ToString().Trim() != "" ? model.DutyCarCount.ToString().Trim() + "辆" : "";
        this.lblDutyCarIntro.Text = model.DutyCarIntro;
        this.lblTaskDate.Text = model.TaskDate.Value.ToShortDateString();
        this.lblProtectCount.Text = model.ProtectCount.ToString() + "平方公厘";
        this.lblMangerDepartment.Text = model.MangerDepartment;
        this.lblFloorUse.Text = model.FloorUse;
        this.lblCadreCount.Text = model.CadreCount.ToString().Trim() != "" ? model.CadreCount.ToString().Trim() + "人" : "";
        this.lblParentDepartment.Text = model.ParentDepartment;
        DepartmentImage.ImageUrl = model.Picture;


        lblMangerDepartment1.Visible = lblMangerDepartment.Visible = model.DepartmentType.Equals("Type03");



        lblEmployeeCount1.Visible = lblEmployeeCount.Visible = !model.DepartmentType.Equals("Type02");
        lblProtectCount1.Visible = lblProtectCount.Visible = !model.DepartmentType.Equals("Type03");
        lblDutyCarIntro1.Visible = lblDutyCarIntro2.Visible = lblDutyCarCount1.Visible = lblDutyCarCount.Visible = !model.DepartmentType.Equals("Type03");
        lblMangerDepartment1.Visible = model.DepartmentType.Equals("Type03");
        lblOfficerCount1.Visible = lblOfficerCount.Visible = !model.DepartmentType.Equals("Type03");
        lblDepartmentAreaSize1.Visible = lblDepartmentAreaSize.Visible = !model.DepartmentType.Equals("Type03");

        lblTaskDate1.Visible = lblTaskDate.Visible = !model.DepartmentType.Equals("Type03");
        lblFloorUse1.Visible = lblFloorUse.Visible = !model.DepartmentType.Equals("Type03");
        lblDutyCarCount1.Visible = lblDutyCarCount.Visible = !model.DepartmentType.Equals("Type03");
        lblCarbarnCount1.Visible = lblCarbarnCount.Visible = !model.DepartmentType.Equals("Type03");
        lblParentDepartment1.Visible = lblParentDepartment.Visible = !model.DepartmentType.Equals("Type03");
        lblContractCount1.Visible = lblContractCount.Visible = model.DepartmentType.Equals("Type01");
    }
    public string GetDepartmentName()
    {
        if (Request["DepartmentID"] == null)
            return "";
        string DepartmentID = Request["DepartmentID"].Substring(0, 2).Equals("13") ? Request["DepartmentID"] : "13" + Request["DepartmentID"];
        return Yipusoft.Account.BLL.Department.GetDepartment(DepartmentID).FullName + "  (点击查看更多图片)";

    }
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        if (Request["departmentID"] == null)
            return;

        string DepartmentID = Request["DepartmentID"].Substring(0, 2).Equals("13") ? Request["DepartmentID"] : "13" + Request["DepartmentID"];
        if (TreeList.SelectedNode.Value.Equals("库室"))
        {
            Response.Redirect("DepartmentImage.aspx?DepartmentID=" + DepartmentID);
        }
        if (TreeList.SelectedNode.Value.Equals("车辆"))
        {
            // Response.Redirect("CartList.aspx?DepartmentID=" + Request["departmentID"]);
            //Response.Redirect("/BasicBase/Vehicle/VehicleList.aspx?where=DepartmentID='" + DepartmentID + "'");
            Response.Redirect("CarList.aspx?DepartmentID=" + DepartmentID);
        }
        if (TreeList.SelectedNode.Value.Equals("人员"))
        {
            //Response.Redirect("NewSoldier.aspx?DepartmentID=" + Request["departmentID"]);
            Response.Redirect("MemberList.aspx?DepartmentID=" + DepartmentID);
        }
        if (TreeList.SelectedNode.Value.Equals("预案"))
        {
            Response.Redirect("/BasicBase/FireProject/FireProjectList.aspx?where=" + "DepartmentID='" + DepartmentID + "'");
        }
        if (TreeList.SelectedNode.Value.Equals("装备器材"))
        {
            DepartmentID = Request["DepartmentID"].Substring(0, 2).Equals("13") ? Request["DepartmentID"] : "13" + Request["DepartmentID"];
            string Where = "departmentid='" + DepartmentID + "'And DeviceCount>0 And Price>0";
            Response.Redirect("/BasicBase/DeviceResult.aspx?Where=" + Where);
        }

        if (TreeList.SelectedNode.Value.Equals("设置库室图片"))
        {
            Response.Redirect("DepartmentManager.aspx?DepartmentID=" + DepartmentID);
        }
        if (TreeList.SelectedNode.Value.Equals("查看库室图片"))
        {
            Response.Redirect("DepartmentImage.aspx?DepartmentID=" + DepartmentID);
        }
        if (TreeList.SelectedNode.Value.Equals("设置单位介绍信息"))
        {


            if (DepartmentID.Substring(5, 2).Equals("00"))
            {
                Response.Redirect("DepartmentIntro2.aspx?DepartmentID=" + DepartmentID);
            }
            Response.Redirect("DepartmentIntro.aspx?DepartmentID=" + DepartmentID);
        }
        if (TreeList.SelectedNode.Value.Equals("抢险救援班"))
        {
            Response.Redirect("ProfessionalTeam/HelpNew.aspx?DepartmentID=" + DepartmentID + "&Type=0");
        }
        if (TreeList.SelectedNode.Value.Equals("灭火攻坚组"))
        {
            Response.Redirect("ProfessionalTeam/Assault.aspx?DepartmentID=" + DepartmentID + "&Type=2");
        }
        if (TreeList.SelectedNode.Value.Equals("灭火抢险救援专业队伍"))
        {
            Response.Redirect("ProfessionalTeam/ProfessionalProc.aspx?DepartmentID=" + DepartmentID);
        }

    }
}
